package com.github.prontera.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.prontera.domain.Tags;
import com.github.prontera.persistence.CrudMapper;
import com.github.prontera.persistence.TagsMapper;
import com.github.prontera.util.Page;

/**
 * 标签
 */
@Service("tagsServce")
public class TagsService extends CrudServiceImpl<Tags>{
    
	Logger logger=Logger.getLogger(TagsService.class);
	
	@Autowired
	private TagsMapper tagsMapper;
    
  	@Autowired
    public TagsService(CrudMapper<Tags> mapper) {
        super(mapper);
    }

  	public List<Tags> findTag(Tags tag){
  		return tagsMapper.findTag(tag);
  	};
  	
  	
	public Page<Tags> page(Tags tags) {
		tags.setOrderBy(" id  desc");
		long count = mapper.count(tags);
		Page<Tags> page = new Page<Tags>(1,5);
		page.setData(mapper.find(tags));
		page.setTotalCount(count);
		return page;
	}

	public int update(Tags tags) {
		int success = tagsMapper.update(tags);
		return success;
	}
	/**
	 * @param gmc
	 * @param 查询父类字典信息
	 * @param dict 字典实体
	 * @return 
	 */
	public Page<Tags> findTagList(Tags tag) {
		tag.setTagType(0);//0-正常
		tag.setOrderBy(" id  asc ");
		
		long count = tagsMapper.count(tag);
		
		if(tag.getPageSize()==null||tag.getPageSize()<2||tag.getPageSize()>100){
			tag.setPageSize(10);
		}
		if(tag.getPageIndex()==null){
			tag.setPageIndex(1);
		}
		Page<Tags> page = new Page<Tags>(tag.getPageIndex(),tag.getPageSize());
		page.setData(tagsMapper.find(tag));
		page.setTotalCount(count);
		return page;
	}
	
	
}
